<?php

namespace app\common\model;
use think\Session;
use think\Model;

class User extends Model
{
    /**
     * 添加到用户表
     * @param $username
     * @param $password
     * @return int
     */
    public function add($username,$password)
    {

        $userModel = new User();
        $userModel->username = $username;
        $userModel->password = MD5($password);
        $res = $userModel->save();

        if ($res) {
            return 5;#注册成功
        }
    }

    /**
     * 验证登陆
     * @param $post
     * @return array|int
     */
        public function check($post)
    {
        $LoginModel = new User();
//        dump($LoginModel);die;

        $res = $LoginModel->where('username', $post['user'])->find();
        if (!$res)
        {

            return  [['message'=>4]];
        }
        if($res['password']!=MD5($post['pw']))
        {
            return [['message'=>5]];
        }
        Session::set('username',$post['user']);
        Session::set('id',$res['id']);

        if ($post['remember']=='on')
        {

        }
        return 1;


    }


}
